package main

import (
	"context"
	"fmt"
	"runtime"
	"time"
)

func main() {
	defer func() {
		fmt.Println("num:", runtime.NumGoroutine())
	}()
	ctx1, cancel := context.WithTimeout(context.Background(), time.Millisecond*1000) // 1000毫秒
	ctx2, _ := context.WithTimeout(ctx1, time.Millisecond*500)                       // 500毫秒

}
func doSomething(ctx context.Context) {
	for {
		select {
		case <-ctx.Done():
			fmt.Println("cancel...:", time.Now().Unix())
			return
		default:
			fmt.Println("default....:", time.Now().Unix())
			time.Sleep(time.Second)
		}
	}
}
